package Classes.GameUtils
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.system.ApplicationDomain;
	import flash.ui.Mouse;
	/**
	 *改变建筑模式的光标类 
	 * * @author 邓坚
	 * 
	 */	
	public class GU_BuildingCursor extends Sprite
	{
		/**
		 *移动建筑时光标Sprite 
		 */
		private var _movePic:Sprite;
		/**
		 *清除建筑时光标Sprite 
		 */
		private var _deletePic:Sprite;
		/**
		 *当前模式，状态 
		 */
		private var _mode:String;
		
		private var _hide:uint=0;
		
		/**
		 *是否显示鼠标在傍边 
		 */
		private var _showMouse:Boolean;
		public function GU_BuildingCursor(mode:String,showMouse:Boolean=true)
		{
			this._showMouse		=	showMouse;
			this._movePic		=	 new (ApplicationDomain.currentDomain.getDefinition("movePic_v") as Class);	
			this._deletePic		=	 new (ApplicationDomain.currentDomain.getDefinition("deletePic_v") as Class);
			this.mouseChildren	=	false;
			this.mouseEnabled	= 	false;
			this.mode	= mode;
			this.reShow();
			super();
		}
		
		/**
		 *刷新
		 * 
		 */
		public function reShow():void
		{
			clear();
			switch(_mode)
			{
				case "moveMode":
					this.addChild(this._movePic);
					break;
				case "cleanMode":
					this.addChild(this._deletePic);
					break;
			}
			this.graphics.endFill();
		}
		
		/**
		 *设置当前模试 
		 * @param value
		 * 
		 */
		public function set mode(value:String):void
		{
			this._mode	=	value;
			this.reShow();
			
		}
		
		public function get mode():String
		{
			return this._mode;
		}
		
		/**
		 *清空 
		 * 
		 */
		public function clear():void
		{
			while(this.numChildren)this.removeChildAt(0);
		}
		
		/**
		 *鼠标移动处理		 
		 * @param e
		 * 
		 */
		public function BBL_Move(e:Event):void
		{
			if(_hide==1){
				show();
			}
			
			if(!_showMouse){
				this.x	= stage.mouseX-this.width/2;
				this.y	= stage.mouseY-this.height/2;
			}
			else{
				this.x	= stage.mouseX+10;
				this.y	= stage.mouseY;
			}
		}
		
		/**
		 *开始改变光标 
		 * 
		 */
		public function start():void
		{
			stage.addEventListener(MouseEvent.MOUSE_MOVE,BBL_Move);
			stage.addEventListener(Event.MOUSE_LEAVE,stagehide);
			if(!_showMouse)Mouse.hide();
		}
		/**
		 *结速改变光标 
		 */
		public function stop():void
		{
		    //trace("光标没了！");
			Mouse.show();
			stage.removeEventListener(MouseEvent.MOUSE_MOVE,BBL_Move);
			stage.removeEventListener(Event.MOUSE_LEAVE,stagehide);
			
			clear();
			this._deletePic		=	null;
			this._movePic		=	null;
	
		}
		
		/**
		 *鼠标离开影片隐藏	_hide=1;
		 * 
		 */
		private function stagehide(e:Event):void
		{
			_hide=1;
			this.visible	= false;
			Mouse.show();	
		}
		/**
		 *图形光标显示 
		 */
		public function show(e:Event=null):void
		{
			_hide=0;
			this.visible	= true;
			if(!_showMouse)Mouse.hide();	
		}
		
		/**
		 *暂时隐藏，让鼠标灰复正常 
		 */
		public function hide(e:Event=null):void
		{
			_hide=2;
			this.visible	= false;
			Mouse.show();	
		}
	}
}